package com.wsl.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 18:03 2018/1/8
 * @Modified by:
 */
@Configuration
public class DataSourceConfig {
    @Bean(name = "dataSource")
    @Qualifier("dataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.fin")
    public DataSource DataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "jdbcTemplate")
    public JdbcTemplate JdbcTemplate(
            @Qualifier("dataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "basedataSource")
    @Qualifier("basedataSource")
    @ConfigurationProperties(prefix = "spring.datasource.base")
    public DataSource BaseDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "basejdbcTemplate")
    public JdbcTemplate BaseJdbcTemplate(
            @Qualifier("basedataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    /**
     * dat老核心的数据库配置
     * @return
     */
    @Bean(name = "olDataSource")
    @Qualifier("olDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.datOld")
    public DataSource olDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "oldJdbcTemplate")
    public JdbcTemplate oldJdbcTemplate(
            @Qualifier("olDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    /**
     * dat  nb数据的配置
     * @return
     */
    @Bean(name = "nbDataSource")
    @Qualifier("nbDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.datnb")
    public DataSource nbDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "nbJdbcTemplate")
    public JdbcTemplate nbJdbcTemplate(
            @Qualifier("nbDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    /**
     * dat  pol数据的配置
     * @return
     */
    @Bean(name = "polDataSource")
    @Qualifier("polDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.datpol")
    public DataSource polDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "polJdbcTemplate")
    public JdbcTemplate polJdbcTemplate(
            @Qualifier("polDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    /**
     * dat  fin数据的配置
     * @return
     */
    @Bean(name = "finDataSource")
    @Qualifier("finDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.datfin")
    public DataSource finDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "finJdbcTemplate")
    public JdbcTemplate finJdbcTemplate(
            @Qualifier("finDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }








}